import math
max = 1001
maxx = 1
for d in xrange(2,max):
    if math.sqrt(d) * math.sqrt(d) == d:
        continue
    print d

    x = int(math.sqrt(d))
    y = 1
    a = x 
    m = 0
    n1 = 1
    d1 = 0  
    dd = 1 
    while x * x - d * y *y != 1:
        m=int(a*d - m)  
        dd=int((d-m*m)/dd)  
        a = int((x+m)/dd)  
  
        n2=n1  
        n1=x  
        d2=d1  
        d1=y  
  
        num=int(a*n1+n2)  
        den=int(a*d1+d2) 
    if num >maxn:  
        maxx=num  
        maxD=D  
print maxx    
